﻿Imports CQRSAzure.EventSourcing
Imports CQRSAzure.IdentifierGroup

''' <summary>
''' Base class for a classifier the decides if an aggregate is in or out of a business meaningful identity group
''' </summary>
''' <typeparam name="TAggregate">
''' The type of the aggregate we are grouping
''' </typeparam>
''' <typeparam name="TAggregateKey">
''' The data type that is used to uniquely identify an instance of the aggregate
''' </typeparam>
''' <remarks>
''' The class derived from this will need to implement the IClassifierEventHandler interface for each event it handles
''' </remarks>
Public MustInherit Class ClassifierBase(Of TAggregate As IAggregationIdentifier, TAggregateKey)
    Implements IClassifier(Of TAggregate)

#Region "private members"
    'Event stream reader to use to evaluate this classifier
    Private ReadOnly m_eventStream As IEventStreamReader(Of TAggregate, TAggregateKey)
#End Region

    ''' <summary>
    ''' Perform the classifier to evaluate if the given aggregate identifier 
    ''' </summary>
    ''' <param name="aggregateInstance">
    ''' The unique instance of the aggregate to evaluate
    ''' </param>
    ''' <returns>
    ''' True if the classifier considers the aggregate to be a member of the group, otherwise false
    ''' </returns>
    Public MustOverride Function IsInGroup(aggregateInstance As TAggregate) As Boolean Implements IClassifier(Of TAggregate).IsInGroup

    ''' <summary>
    ''' Perform the classifier to evaluate if the given aggregate identifier 
    ''' </summary>
    ''' <param name="aggregateInstance">
    ''' The unique instance of the aggregate to evaluate
    ''' </param>
    ''' <param name="AsOf">
    ''' The effective date that we are evaluating the membership for (we run the event stream up until that point)
    ''' </param>
    ''' <returns>
    ''' True if the classifier considers the aggregate to be a member of the group, otherwise false
    ''' </returns>
    Public MustOverride Function IsInGroup(aggregateInstance As TAggregate, AsOf As Date) As Boolean Implements IClassifier(Of TAggregate).IsInGroup

    ''' <summary>
    ''' Create a new classifier that can use the given event stream reader to decide if an aggregate is in or out of an identity group
    ''' </summary>
    ''' <param name="streamReader">
    ''' The aggregate event stream reader to use to ghet teh events in order to evaluate if an aggregate is in or out of the identity group
    ''' </param>
    Public Sub New(ByVal streamReader As IEventStreamReader(Of TAggregate, TAggregateKey))
        m_eventStream = streamReader

    End Sub

End Class
